package com.vpen.picupload.controller;

import com.vpen.picupload.annotation.ColorAnnotation;
import com.vpen.picupload.annotation.History;
import com.vpen.picupload.entity.User;
import com.vpen.picupload.enums.Color;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.objects.annotations.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.websocket.server.PathParam;

/**
 * -@Version 1.0
 * -@Author:Vpen
 * -@Date:2021/7/31 23:07
 * -@Content:
 */
@Slf4j
@RestController
public class HelloWorld {

    @GetMapping("/hello/{id}/{name}/{age}")
    @History(operation = 1, username = "Vpen")
    public String hello(@PathVariable("id") Integer id,
                        @PathVariable("name") String name,
                        @PathVariable("age") Float age, HttpServletRequest request){
        log.info("hello");
        int userId = 123;
        
        return "hello";
    }

    @GetMapping("/hello2/{id}/{name}/{age}")
    @History(operation = 11, username = "131")
    public String hello2(@PathVariable("id") Integer id,
                        @PathVariable("name") String name,
                        @PathVariable("age") Float age, HttpServletRequest request){
        log.info("hello");
        int userId = 123;
        return "hello";
    }

    @ApiOperation("el表达式")
    @GetMapping("/hello")
    /**
    * @author: 韦鹏
    * @name: get
    * @date: 2021/8/6 22:37
    * @param: [user, color, name]
    * @return: java.lang.String
    * @作用: #name绑定了参数name，#user.id 绑定了user，在方法体里内设置id的值，aop能动态拿到值
    **/
    @ColorAnnotation(type = Color.GREEN,name = "#name",password = "#pass",id = "#user.id")
    public String get(User user,@RequestParam("color") Color color, @RequestParam("name")String name){
        user.setId(123);
        return "hello";
    }

}
